package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ScrewConfig;
import com.ruoyi.system.service.IScrewConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * screwConfigController
 * 
 * @author 李奎
 * @date 2023-11-13
 */
@RestController
@RequestMapping("/system/screwConfig")
public class ScrewConfigController extends BaseController {
    @Autowired private IScrewConfigService screwConfigService;

    /**
     * 查询screwConfig列表
     */
    @PreAuthorize("@ss.hasPermi('system:screwConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScrewConfig screwConfig) {
        startPage();
        List<ScrewConfig> list = screwConfigService.selectScrewConfigList(screwConfig);
        return getDataTable(list);
    }

    /**
     * 导出screwConfig列表
     */
    @PreAuthorize("@ss.hasPermi('system:screwConfig:export')")
    @Log(title = "screwConfig", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScrewConfig screwConfig) {
        List<ScrewConfig> list = screwConfigService.selectScrewConfigList(screwConfig);
        ExcelUtil<ScrewConfig> util = new ExcelUtil<ScrewConfig>(ScrewConfig.class);
        util.exportExcel(response, list, "screwConfig数据");
    }

    /**
     * 获取screwConfig详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:screwConfig:query')")
    @GetMapping(value = "/{screwId}")
    public AjaxResult getInfo(@PathVariable("screwId") Long screwId) {
        return AjaxResult.success(screwConfigService.selectScrewConfigByScrewId(screwId));
    }

    /**
     * 新增screwConfig
     */
    @PreAuthorize("@ss.hasPermi('system:screwConfig:add')")
    @Log(title = "screwConfig", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScrewConfig screwConfig) {
        return toAjax(screwConfigService.insertScrewConfig(screwConfig));
    }

    /**
     * 修改screwConfig
     */
    @PreAuthorize("@ss.hasPermi('system:screwConfig:edit')")
    @Log(title = "screwConfig", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScrewConfig screwConfig) {
        return toAjax(screwConfigService.updateScrewConfig(screwConfig));
    }

    /**
     * 删除screwConfig
     */
    @PreAuthorize("@ss.hasPermi('system:screwConfig:remove')")
    @Log(title = "screwConfig", businessType = BusinessType.DELETE)
	@DeleteMapping("/{screwIds}")
    public AjaxResult remove(@PathVariable Long[] screwIds) {
        return toAjax(screwConfigService.deleteScrewConfigByScrewIds(screwIds));
    }



    /**
     * 生成文档
     */
    @PreAuthorize("@ss.hasPermi('system:screwConfig:query')")
    @GetMapping(value = "/generateDocument/{screwId}")
    public AjaxResult generateDocument(@PathVariable("screwId") Long screwId) {
        return AjaxResult.success(screwConfigService.generateDocument(screwId));
    }
}
